//service统一出口
import HYRequest from "./request"
import {BASE_URL , TIME_OUT} from './request/config'
import localCache from '@/utils/cache'

const hyRequest = new HYRequest({
  baseURL:BASE_URL,
  timeout:TIME_OUT,
  interceptors: {
    //请求成功
    requestInterceptor: (config) => {

      //是否有token
      const token = localCache.getCache('token')
      if(token) {
        const data = {
          'Authorization':`Bearer ${token}`
        }
        config.headers = data
        // config.headers = token
      }
      return config
    },
    //请求失败
    requestInterceptorCatch: (err) => {
      console.log('请求失败')
      return err
    },
    //响应成功
    responseInterceptor: (res) => {
      console.log('响应成功')
      return res
    },
    //响应失败
    responseInterceptorCatch: (err) => {
      console.log('响应失败')
      return err
    }
  }
})

export default hyRequest
